<div class="main fly-user-main layui-clear">
    <include file="Common:sidebar" />
    <div class="site-tree-mobile layui-hide">
        <i class="layui-icon">
            
        </i>
    </div>
    <div class="site-mobile-shade">
    </div>
    <div lay-filter="user" class="layui-tab layui-tab-brief">
        <ul id="LAY_mine" class="layui-tab-title">
            <li hash="info" class="layui-this">
                我的资料
            </li>
            <li hash="avatar">
                头像
            </li>
            <li hash="pass">
                密码
            </li>
            <li hash="bind">
                帐号绑定
            </li>
        </ul>
        <div style="padding: 20px 0;" class="layui-tab-content">
            <div class="layui-form layui-form-pane layui-tab-item layui-show">
                <form method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="L_email">
                            邮箱
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" value="{$email}" autocomplete="off"
                            lay-verify="email" required="" name="email" id="L_email">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            如果您在邮箱已激活的情况下，变更了邮箱，需
                            <a style="font-size: 12px; color: #4f99cf;" href="javascript:void(0);" onclick="actiEmail();">
                                重新验证邮箱
                            </a>
                            。
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="L_username">
                            昵称
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" value="{$_SESSION['nickname']}" autocomplete="off"
                            lay-verify="nickname" required="" name="nickname" id="L_username">
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="radio" title="男" value="男" name="sex" <?php if ($sex == '男') {echo 'checked';} ?>>
                                <div class="layui-unselect layui-form-radio">
                                    <i class="layui-anim layui-icon">
                                        
                                    </i>
                                    <span>
                                        男
                                    </span>
                                </div>
                                <input type="radio" title="女" value="女" name="sex" <?php if ($sex == '女') {echo 'checked';} ?>>
                                <div class="layui-unselect layui-form-radio">
                                    <i class="layui-anim layui-icon">
                                        
                                    </i>
                                    <span>
                                        女
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="L_city">
                            城市
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" value="{$city}" autocomplete="off"
                            name="city" id="L_city">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label" for="L_sign">
                            签名
                        </label>
                        <div class="layui-input-block">
                            <textarea style="height: 80px;" class="layui-textarea" autocomplete="off"
                            name="sign" id="L_sign" placeholder="随便写些什么刷下存在感"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button lay-submit="" lay-filter="change-uinfo" key="set-mine" class="layui-btn">
                            确认修改
                        </button>
                    </div>
                </form>
            </div>
            <div class="layui-form layui-form-pane layui-tab-item">
                <div class="layui-form-item">
                    <div id="avatar-add"></div>
                    <script src="__PUBLIC__/xiuxiu.js" type="text/javascript"></script>
                    <script type="text/javascript">
                        $(function () {
                            var old_avatar = $('#avatar-pic').attr('src');
                            /*第1个参数是加载编辑器div容器，第2个参数是编辑器类型，第3个参数是div容器宽，第4个参数是div容器高*/
                            xiuxiu.embedSWF("avatar-add", 5, "600px", "500px");
                            //修改为您自己的图片上传接口
                            path = "http://<?php echo $_SERVER['HTTP_HOST']; ?>{:U('home/ucenter/newavatar')}";
                            // alert(path);
                            xiuxiu.setUploadURL(path);
                            xiuxiu.setUploadType(2);
                            xiuxiu.setUploadDataFieldName("upload_file");
                            xiuxiu.onInit = function() {
                                avatarUrl = "http://<?php echo $_SERVER['HTTP_HOST']; ?>__ROOT__/<?php echo $_SESSION['avatar']; ?>";
                                xiuxiu.loadPhoto(avatarUrl); //修改为要处理的图片url
                            }
                            xiuxiu.onUploadResponse = function(data) {
                                if (data == '0') {
                                    layer.msg('上传失败', {icon: 5});
                                } else {
                                    layer.msg('上传成功', {icon: 6});
                                    path = "__ROOT__/" + data;
                                    $('#avatar-pic').attr('src', path);
                                }
                            }
                        });
                    </script>
                </div>
            </div>
            <div class="layui-form layui-form-pane layui-tab-item">
                <div class="layui-form-item">
                    <label class="layui-form-label" for="L_nowpass">
                        当前密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" class="layui-input" autocomplete="off" lay-verify="nowpassword"
                        required="" name="nowpass" id="L_nowpass">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="L_pass">
                        新密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" class="layui-input" autocomplete="off" lay-verify="password"
                        required="" name="pass" id="L_pass">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        6到12个字符
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="L_repass">
                        确认密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" class="layui-input kass" autocomplete="off" lay-verify="repassword"
                        required="" name="repass" id="L_repass">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button lay-submit="" lay-filter="change-pwd" key="set-mine" class="layui-btn">
                        确认修改
                    </button>
                </div>
            </div>
            <div class="layui-form layui-form-pane layui-tab-item">
                <ul class="app-bind">
                    <li class="fly-msg  ">
                        <i class="iconfont icon-qq">
                        </i>
                        <?php if($create_for_qq == 0){?>
                        <a type="qq_id" class="acc-bind" onclick="layer.msg('正在绑定微博QQ', {icon:16, shade: 0.1, time:0})"
                        href="{:U('/home/login/qqlogin')}">
                            立即绑定
                        </a>
                        <span>
                            ，即可使用QQ帐号登录Fly社区
                        </span>
                        <?php } else { ?>
                        <span>
                            已经绑定QQ
                        </span>
                        <?php } ?>
                    </li>
                    <li class="fly-msg ">
                        <i class="iconfont icon-weibo">
                        </i>
                        <a onclick="layer.msg('正在绑定微博', {icon:16, shade: 0.1, time:0})" type="weibo_id"
                        class="acc-weibo" href="{:U('/home/login/weibo')}">
                            立即绑定
                        </a>
                        <span>
                            ，即可使用微博帐号登录Fly社区
                        </span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use('form', function(){
        var form = layui.form()
        ,layer = layui.layer;
        //表单验证
        form.verify({
            nickname: function(value) {
                if ($('#L_username').val() != '') {
                    if (!(/^[a-zA-Z\u4e00-\u9fa5\\s·]{1}[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$/.test(value))) {
                        return '昵称不合要求';
                    }
                } else {
                    return '昵称不能为空';
                }
            },
            nowpassword: function(value) {
                if (value == '') {
                    return '密码不能为空';
                }
            },
            password: function(value) {
                if (value != '') {
                    if (!(/^[\S]{6,12}$/.test(value))) {
                        return '密码长度不合要求';
                    } else {
                        if (value == $('#L_nowpass').val()) {
                            return '新旧密码不可一致';
                        }
                    }
                } else {
                    return '密码不能为空';
                }
            },
            repassword: function (value) {
                if (value != '') {
                    if (value != $('#L_pass').val()) {
                        return '重复密码不一致';
                    }
                } else {
                    return '重复密码不能为空';
                }
            }
        });
        //监听提交密码修改
        form.on('submit(change-pwd)', function(data){
            console.log(data.field);
            $.ajax({
                url: "{:U('home/ucenter/checkpwd')}",
                type: 'POST',
                dataType: 'json',
                data: data.field,
            })
            .done(function(response) {
               if(response.error){
                    layer.msg(response.error, {icon: 5});
               }else if (response.info) {
                    layer.msg(response.info, {icon: 6});
               }
            })
            .fail(function(response) {
                console.log(response);
            });
            return false;
        });
        //监听提交用户信息修改
        form.on('submit(change-uinfo)', function(data){
            // console.log(data.field);
            $.ajax({
                url: "{:U('home/ucenter/checkuinfo')}",
                type: 'POST',
                dataType: 'json',
                data: data.field,
            })
            .done(function(response) {
               if(response.error){
                    layer.msg(response.error, {icon: 5});
               }else if (response.info) {
                    $('cite').text(response.nickname);
                    layer.msg(response.info, {icon: 6});
               }
            })
            .fail(function(response) {
                console.log(response);
            });
            return false;
        });
    });
    function actiEmail() {
        layer.msg('正在发送激活邮件', {icon:16, time:0});
        $.ajax({
            url: "{:U('home/ucenter/activate')}",
            type: 'POST',
            dataType: 'json',
        })
        .done(function(response) {
            if (response.error) {
                layer.msg(response.error, {icon: 5});
                console.log(response.errorInfo);
            } else {
                layer.msg(response.info, {icon: 6});
            }
        })
        .fail(function(response) {
            console.log("error"+response);
        });
    }
</script>